<?php

/*
 * 作者:liuleyi
 * 功能描述:原材料控制器
 * 修改记录
 * 修改时间   修改人     修改描述
 */

namespace Admin\Controller;

use Think\Controller;

class MaterialController extends Controller {

    public function add() {
        if (!empty($_POST)) {
            $MaterialID = get_guid(__FUNCTION__);
            $func = new \Admin\Func\Func904020201($MaterialID, I('MaterialCode'), I('MaterialName'), I('MaterialTypeID'), I('MaterialModel'), I('MaterialUnit'), I('MaterialIMG'), I('MaterialSIMG'), I('MaterialDesc'));

            if ($func->execute() === false) {
                $this->error("新增失败:" . $func->getErrMsg());
            } else {
                // $this->display();
                $this->success('新增成功！');
            }
            //  $this->display();
        } else {
            $location = new \Admin\Func\Func999010102(VAR_904020201);
            $location->execute();
            $this->assign(LOCATION, $location->getRst());
            $LSTMATERIALTYPEID = new \Admin\Func\Func999010103(VAR_MATERIALTYPEID);
            $LSTMATERIALTYPEID->execute();
            $this->assign('LSTMATERIALTYPEID', $LSTMATERIALTYPEID->getRst());
            $this->assign('GV_Enum', $GLOBALS['GV_Enum']);
            $this->display();
        }
    }

    public function del($MaterialID) {
        $func = new \Admin\Func\Func904020203($MaterialID);
        if ($func->execute() === false) {
            $this->error('删除失败' . $func->getErrMsg());
        } else {
            $this->redirect('Material/lst');
        }
    }

    public function edit($MaterialID) {
        if (!empty($_POST)) {
            $func = new \Admin\Func\Func904020202(I('MaterialID'), I('MaterialCode'), I('MaterialName'), I('MaterialTypeID'), I('MaterialModel'), I('MaterialUnit'), I('MaterialIMG'), I('MaterialSIMG'), I('MaterialDesc'));
            if ($func->execute() === false) {
                $this->error("编辑失败:" . $func->getErrMsg());
            } else {
                $this->success('编辑成功！');
            }
        } else {

            $func = new \Admin\Func\Func904020204($MaterialID);
            if ($func->execute() === false) {
                $this->error('查询失败:' . $func->getErrMsg());
            } else {
                $location = new \Admin\Func\Func999010102(VAR_904020202);
                $location->execute();
                $this->assign(LOCATION, $location->getRst());

                $LSTMATERIALTYPEID = new \Admin\Func\Func999010103(VAR_MATERIALTYPEID);
                $LSTMATERIALTYPEID->execute();
                $this->assign('LSTMATERIALTYPEID', $LSTMATERIALTYPEID->getRst());

                $this->assign(GV_ENUM, $GLOBALS[GV_ENUM]);
                $this->assign(POST, $func->getRst()[0]);
                $this->display();
            }
        }
    }

    public function lst() {
        $func = new \Admin\Func\Func904020205(I('MaterialCode'), I('MaterialName'), I('MaterialTypeID'));
        if ($func->execute() === false) {
            $this->error('查询失败:' . $func->getErrMsg());
        } else {
            $location = new \Admin\Func\Func999010102(VAR_904020205);
            $location->execute();
            $this->assign(LOCATION, $location->getRst());

            $LSTMATERIALTYPEID = new \Admin\Func\Func999010103(VAR_MATERIALTYPEID);
            $LSTMATERIALTYPEID->execute();

            $this->assign('LSTMATERIALTYPEID', $LSTMATERIALTYPEID->getRst());
            $this->assign(GV_ENUM, $GLOBALS[GV_ENUM]);
            $this->assign(LST, $func->getRst());
        }
        $this->display();
    }

}
